package com.example.myspringboot;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author cy
 * @date 2024/3/8
 */
public class SqlJdbc {

    @Before
    public void init() {
        System.out.println("init");
    }

    @After
    public void destroy() {
        System.out.println("destroy");
    }

    @Test
    public void test() throws Exception{
        try {
            String command = "cmd /c dir"; // 要执行的CMD命令
            Process process = Runtime.getRuntime().exec(command);

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

            int exitCode = process.waitFor();
            System.out.println("Exited with error code " + exitCode);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
